#include "board_hardware_config.h"

//#define FLASH_PROTECT
__asm void SystemReset(void)
{
    MOV R0, #1           //; 
    MSR FAULTMASK, R0    //; ??FAULTMASK ????????
    LDR R0, =0xE000ED0C  //;
    LDR R1, =0x05FA0004  //; 
    STR R1, [R0]         //; ??????   
 
deadloop
    B deadloop        //; ???????????????
}

void board_init(void)
{

	/* Enable GPIOA */
	RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_GPIOA, ENABLE);

    /* Enable GPIOB */
	RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_GPIOB, ENABLE);

	/* Enable GPIOC clock */
	RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_GPIOC, ENABLE);

	
    /*USART1 clocks*/
    RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_USART1, ENABLE);
    
	/*USART2 clocks */
	RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_USART2, ENABLE);
		
    debug_init(115200);
    SysTick_Configuration();
    dev_uart1_init(115200);

		
		#ifdef FLASH_PROTECT

    if(FLASH_GetReadOutProtectionStatus() == RESET)
		{	 
				 FLASH_Unlock();
	//         _uartstrout(0,"\r\n Flash not read protect and flow set protect");
			 if(FLASH_ReadOutProtection(ENABLE) == FLASH_COMPLETE)
			 {
	//		     _uartstrout(0,"\r\nFlash Set Read protect success"); 
			 }
	//		 SystemReset();
				FLASH_Lock();	
		}
		else
		{
	//		 _uartstrout(0,"\r\nFlash  read protect");

		}

    #endif 
	
    
}

